package yb.ecp.fast.infra.infra.monitor;

import yb.ecp.fast.infra.infra.log.LogHelper;

import java.io.File;

/**
 * @author wanghao
 * @Description 监控内存使用情况
 * @date 2018-02-13 9:09
 */
public abstract class MemoryMonitor {
    private static final int MEGA = 1024 * 1024;

    public static void takeMemoryLog() {
        LogHelper.monitor("Available processors (cores): " +
                Runtime.getRuntime().availableProcessors());

        LogHelper.monitor("Free memory (MB): " +
                Runtime.getRuntime().freeMemory() / MEGA);

  /* This will return Long.MAX_VALUE if there is no preset limit */
        long maxMemory = Runtime.getRuntime().maxMemory();
  /* Maximum amount of memory the JVM will attempt to use */
        LogHelper.monitor("Maximum memory (MB): " +
                (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory / MEGA));

  /* Total memory currently in use by the JVM */
        LogHelper.monitor("Total memory (MB): " +
                Runtime.getRuntime().totalMemory() / MEGA);
    }

    public abstract void scheduleMonitor();
}
